#ifndef __TETRIS_BOARD_H__
#define __TETRIS_BOARD_H__

#include "OgreMemoryAllocatorConfig.h"
#include "OgreFrameListener.h"
#include <list>

struct tCube
{
	Ogre::SceneNode*	pNodeCube;

	tCube()
	:	pNodeCube(NULL)
	{
	}

	tCube(Ogre::SceneNode* node)
	:	pNodeCube(node)
	{
	}
};

class cTetrisPiece;

class cTetrisBoard : public Ogre::Singleton<cTetrisBoard> ,  public Ogre::UtilityAlloc, public Ogre::FrameListener
{
public:	
			cTetrisBoard();
			virtual ~cTetrisBoard();

			bool	frameStarted		(const Ogre::FrameEvent& evt);
			bool	frameEnded			(const Ogre::FrameEvent& evt);

			DWORD	GetCollissionType	(cTetrisPiece& piece,			  const Ogre::Vector3& vDist);
			DWORD	GetCollissionType	(const Ogre::AxisAlignedBox& box, const Ogre::Vector3& vDist);

			bool	CanRotatePiece		(cTetrisPiece& piece, const Ogre::Vector3& vAxis, const Ogre::Radian& radian);
			bool	IsCollision			(cTetrisPiece& piece, const Ogre::Vector3& vDist);
			DWORD	CubeCollision		(cTetrisPiece& piece, const Ogre::Vector3& vDist);
			bool	IsCollision			(const Ogre::AxisAlignedBox& aabb);
			bool	IsEmpty				();
			bool	BreakPiece			(cTetrisPiece& piece, const Ogre::Vector3& vLastDir);
			void	AdjustPiece			(cTetrisPiece& piece, const Ogre::Vector3& vAdjustDir);
			float	GetAdjustValue		(const Ogre::AxisAlignedBox& aabb, const Ogre::Vector3& vAdjustDir);
			void	PrintDebugGrid		();			
			void	ClearAll			(Ogre::SceneManager* pSceneMgr);			
			int		CheckForLines		();
			int		DeleteLines			(Ogre::SceneManager* pSceneMgr);
private:
	tCube			 m_Grid[MOD_GRID_LINES][MOD_GRID_COLUMN];

	Ogre::Plane		m_LeftPlane;
	Ogre::Plane		m_RightPlane;
	Ogre::Plane		m_DownPlane;

	Ogre::AxisAlignedBox	m_aabb;
	Ogre::Vector3			m_vMin;
	Ogre::Vector3			m_vMax;
};

#endif // __TETRIS_BOARD_H__